package com.atguigu.q_cas01;

import java.util.concurrent.atomic.AtomicInteger;

public class Cas01 {
    public static void main(String[] args) {
        AtomicInteger atomicInteger = new AtomicInteger(5);

        /*
        * 比较并交换
        * 如果预期值与内存的值相同 则交换 如果不同则不交换*/
        boolean b = atomicInteger.compareAndSet(5, 20);
        System.out.println(b+","+atomicInteger.get()); // true
        boolean b1 = atomicInteger.compareAndSet(5, 21);
        System.out.println(b1); // false
        boolean b2 = atomicInteger.compareAndSet(20, 21);
        System.out.println(b2); // true
    }
}
